<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
		
				
				<table class="table table-condensed table-bordered table-hover" id="grid_tag">
					<tr>
						<th><input type="checkbox" name="checkAll" onclick="checkAll();"></th>
						<th>名称</th>
						<th>显示条数</th>
						<th>样式</th>
						<th>
							<button id="add_btn" class="btn btn-small btn-primary" onclick="add('tag')">添加</button>
							<button id="del_btn" class="btn btn-small btn-primary" onclick="del('tag');">删除</button>
						</th>
					</tr>
					<c:forEach items="${pageModel.list }" var="tag">
						<tr dataid=${tag.id }>
							<td align="center" width="20">
								<input type="checkbox" name="ck" onclick="checkOne();">
							</td>
							<td dataType="name">${tag.name}</td>
							<td dataType="pagesize">${tag.pagesize}</td>
							<td dataType="css" style="${tag.css}">${tag.css}</td>
							<td>
								<button class="btn btn-small" onclick="edit('tag',${tag.id})">修改</button>
							</td>
						</tr>
					</c:forEach>
				</table>
    
<script type="text/javascript">
$(document).ready(function() {
	//$("td").click(tdclick); 
});
function tdclick(){  
    var td = $(this);  
    var text = td.text().trim();  
    td.html("");
    var input = $("<input type='text'/>");  
    input.attr("value",text);
    td.append(input);  
    td.unbind("click"); 
    input.keyup(function(event){  
        var myEvent = event;  
        var key = myEvent.keyCode;  
        if(key == 13){  
            var inputNode = $(this);  
            var inputText = inputNode.val();  
            inputNode.parent().html(inputText);  
            td.click(tdclick); 
            ajaxCommit(td,inputText);
        }  
    });
    input.blur(function(){  
        var inputNode = $(this);  
        var inputText = inputNode.val();  
        inputNode.parent().html(text);  
        td.click(tdclick);  
    }); 
    td.parents("tr").popover('destroy');
}  

function ajaxCommit(td,inputText){
	 var id=td.parents("tr").attr("dataid");
	 var dataType=td.attr("dataType");
	 if(dataType=="name"){
		 $.post("/content/tag/save",{id:id,name:inputText},function(data){
			 if(data=='success'){
				 td.parents("tr").popover('show');
			 }
		 });
	 }else if(dataType=="pagesize"){
		 $.post("/content/tag/save",{id:id,pagesize:inputText},function(data){
			 if(data=='success'){
				 td.parents("tr").popover('show');
			 }
		 });
	 }else if(dataType=="css"){
		 $.post("/content/tag/save",{id:id,css:inputText},function(data){
			 if(data=='success'){
				 td.parents("tr").popover('show');
			 }
		 });
	 }
     
}
</script>
